home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Sockets / tcpglue.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-05  |  3.1 KB  |  152 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    Glue routines to call the MacTCP drivers
  3.  *    
  4.  *    Summer 1989, Tom Milligan, University of Toronto Computing Services
  5.  */
  6.  
  7.      
  8. #include <MacTCPCommonTypes.h>
  9. #include <GetMyIPAddr.h>
  10. #include <TCPPB.h>
  11. #include <UDPPB.h>
  12. #include <AddressXlation.h>
  13.  
  14. #define xOpenDriver(driver,bad) \
  15. { \
  16.     char ipdriver[6]; \
  17.     if (driver == 0) \
  18.     { \
  19.         ParamBlockRec pb; \
  20.         OSErr io; \
  21.         pb.ioParam.ioCompletion = 0L; \
  22.         ipdriver[0] = 4; \
  23.         ipdriver[1] = '.'; \
  24.         ipdriver[2] = 'i'; \
  25.         ipdriver[3] = 'p'; \
  26.         ipdriver[4] = 'p'; \
  27.         ipdriver[5] = 0; \
  28.         pb.ioParam.ioNamePtr = ipdriver; \
  29.         pb.ioParam.ioPermssn = fsCurPerm; \
  30.         io = PBOpen(&pb,false); \
  31.         if (io != noErr) \
  32.             return(bad); \
  33.         driver = pb.ioParam.ioRefNum; \
  34.     } \
  35. }
  36.  
  37. #if GLUE_DEBUG > 0
  38. #define xPBControl(pb,completion) \
  39. { \
  40.     OSErr io; \
  41.     if (completion == 0L) \
  42.     { \
  43.         (pb)->ioCompletion = 0L; \
  44.         dprintf("about to PBControl(%d,sync)\n",pb->csCode); \
  45.         io = PBControl((ParmBlkPtr)(pb),false); \
  46.     } \
  47.     else if (completion == (TCPIOCompletionProc)-1L) \
  48.     { \
  49.         (pb)->ioCompletion = 0L; \
  50.         dprintf("about to PBControl(%d,async) no completion routine\n",pb->csCode); \
  51.         io = PBControl((ParmBlkPtr)(pb),true);     \
  52.     } \
  53.     else \
  54.     {  \
  55.         (pb)->ioCompletion = completion; \
  56.         dprintf("about to PBControl(%d,async) completion routine %08x\n",pb->csCode,(pb)->ioCompletion); \
  57.         io = PBControl((ParmBlkPtr)(pb),true);     \
  58.     } \
  59.     dprintf("PBControl done code %d\n",io); \
  60.     return(io); \
  61. }
  62. #define xPBControlSync(pb,io) \
  63. { \
  64.     (pb)->ioCompletion = 0L; \
  65.     dprintf("about to PBControl(%d,sync)\n",pb->csCode); \
  66.     io = PBControl((ParmBlkPtr)(pb),false); \
  67.     dprintf("PBControl done code %d\n",io); \
  68. }
  69.  
  70. #else
  71.  
  72. #define xPBControl(pb,completion) \
  73. { \
  74.     if (completion == 0L) \
  75.     { \
  76.         (pb)->ioCompletion = 0L; \
  77.         return(PBControl((ParmBlkPtr)(pb),false)); \
  78.     } \
  79.     else if (completion == (TCPIOCompletionProc)-1L) \
  80.     { \
  81.         (pb)->ioCompletion = 0L; \
  82.         return(PBControl((ParmBlkPtr)(pb),true));     \
  83.     } \
  84.     else \
  85.     {  \
  86.         (pb)->ioCompletion = completion; \
  87.         return(PBControl((ParmBlkPtr)(pb),true));     \
  88.     } \
  89. }
  90. #define xPBControlSync(pb,io) \
  91. { \
  92.     (pb)->ioCompletion = 0L; \
  93.     io = PBControl((ParmBlkPtr)(pb),false); \
  94. }
  95.  
  96. #endif GLUE_DEBUG
  97.  
  98. #define TCPStateClosed         0
  99. #define TCPStateListen         2
  100. #define TCPStateSynReceived     4
  101. #define TCPStateSynSent         6
  102. #define TCPStateEstablished     8
  103. #define TCPStateFinWait1    10
  104. #define TCPStateFinWait2    12
  105. #define TCPStateCloseWait    14
  106. #define TCPStateClosing        16
  107. #define TCPStateLastAck        18
  108. #define TCPStateTimeWait    20
  109.  
  110. OSErr xTCPCreate(
  111.     int buflen,
  112.     TCPNotifyProc notify,
  113.     TCPiopb *pb);
  114.     
  115. OSErr xTCPPassiveOpen(
  116.     TCPiopb *pb, 
  117.     short port,
  118.     TCPIOCompletionProc completion);
  119.     
  120. OSErr xTCPActiveOpen(
  121.     TCPiopb *pb, 
  122.     short port,
  123.     long rhost,
  124.     short rport,
  125.     TCPIOCompletionProc completion);
  126.     
  127. OSErr xTCPRcv(
  128.     TCPiopb *pb,
  129.     Ptr buf, 
  130.     int buflen,
  131.     TCPIOCompletionProc completion);
  132.     
  133. OSErr xTCPSend(
  134.     TCPiopb *pb,
  135.     wdsEntry *wds, 
  136.     Boolean push,
  137.     Boolean urgent,
  138.     TCPIOCompletionProc completion);
  139.     
  140. OSErr xTCPRelease(TCPiopb *pb);
  141.     
  142. int xTCPBytesUnread( TCPiopb *pb);
  143.     
  144. void xTCPInfo(TCPiopb *pb);
  145.  
  146. ip_addr xIPAddr();
  147.  
  148. long xNetMask();
  149.  
  150. unsigned short xMaxMTU();
  151.  
  152.